'''
工地档案
'''
from Lib.base.page_object.site_record.site_list import SiteRecord
from selenium.webdriver.common.by import By
import allure
import os
from Lib.common.assert_class import AssertClass
import pytest


@pytest.fixture(scope='class', autouse=True)
@pytest.mark.usefixtures('login')
def set_cls(login):
    TestSiteRecord.assert_class = AssertClass(login)
    TestSiteRecord.siteRecord = SiteRecord(login)


@allure.feature('建筑工地页面测试')
class TestSiteRecord:

    @allure.title('查询工地档案列表')
    def test_01_site_record_list(self):
        '''
        查询工地档案列表
        :return:
        '''
        self.siteRecord.site_record_list()
        # 设置断言
        assert_args = (By.XPATH, '//table[@class="rz-table__body"]//tr[1]//div[@title="房屋建筑"]')
        self.assert_class.make_assert_by_text(args=assert_args, assert_data='房屋建筑', context="查询工地档案列表")

    @allure.title('搜索工地列表并查看详情')
    def test_02_site_record_search_and_detail(self):
        '''
        搜索工地列表并查看详情
        :return:
        '''
        self.siteRecord.site_record_search_detail()
        # 设置断言
        assert_args = (By.XPATH, '//div[contains(@class, "last-crumbs-item")]//span[@class="title"]')
        self.assert_class.make_assert_by_text(args=assert_args, assert_data='详情', context="查询工地档案列表")

    @allure.title('搜索工地并修改工地分类分级')
    def test_03_site_record_search_and_update(self):
        '''
        搜索工地并修改工地分类分级
        :return:
        '''
        self.siteRecord.site_record_search_update()
        # 设置断言
        assert_args = (
            By.XPATH, '//div[@class="rz-tabs__content"]//div[contains(text(), "分级分类")]/..//span[contains(text(), "1")]')
        self.assert_class.make_assert_by_text(args=assert_args, assert_data='1', context="修改工地分级分类")


if __name__ == '__main__':
    pytest.main(['-v', './site-record_test.py', '--alluredir', '../result', '--clean-alluredir'])
    os.system(r'copy ..\config\environment.properties ..\result\environment.properties')
    os.system('allure generate  ../result -o ../report/ --clean')
